// Copyright (c) 2007-2008, 
// Trevor McCauley, http://www.senocular.com, 
// Alessandro Crugnola, http://www.sephiroth.it,
// Marc Speck, http://www.faindu.com
// All Rights Reserved. The following is Source Code and is subject to all restrictions 
// on such code as contained in the license accompanying this product.
package com.faindu.editImage.scale
{
	import com.faindu.editImage.base.BaseControl;
	import com.faindu.editImage.base.BaseTool;
	
	import flash.events.Event;
	import flash.geom.Matrix;
	import flash.geom.Point;

/**
 * The user drags these "buttons" to edit the image. Scale controls are square.
 */
public class ScaleControl extends BaseControl
{
	/**
	 * Constructor
	 */
	function ScaleControl( interactionMethod:Function, referenceName:String ) 
	{
		super( interactionMethod, referenceName )
		cursor = new ScaleCursor( referenceName )
	}

	/**
	 * @inheritDoc
	 */
	override public function draw( event:Event=null ): void 
	{
		super.draw()
		
		graphics.clear()
		graphics.lineStyle( 1, 0xf8f8f8 )
		graphics.beginFill( 0x222222 )
		
		const size:Number  = editImage.controlSize
		const size2:Number = size/2
		graphics.drawRect(-size2, -size2, size, size)
		graphics.endFill()
		
		var rotationCenter: Point
		
		switch ( referenceName )
		{
			case BaseTool.LEFT:
				rotationCenter = editImage.controlsPositions.left
				break;
				
			case BaseTool.TOP:
				rotationCenter = editImage.controlsPositions.top
				break;
				
			case BaseTool.RIGHT:
				rotationCenter = editImage.controlsPositions.right
				break;
				
			case BaseTool.BOTTOM:
				rotationCenter = editImage.controlsPositions.bottom
				break;
				
			case BaseTool.TOP_LEFT:
				rotationCenter = editImage.controlsPositions.topLeft
				break;
			
			case BaseTool.TOP_RIGHT:
				rotationCenter = editImage.controlsPositions.topRight
				break;
				
			case BaseTool.BOTTOM_RIGHT:
				rotationCenter = editImage.controlsPositions.bottomRight
				break;
				
			case BaseTool.BOTTOM_LEFT:
				rotationCenter = editImage.controlsPositions.bottomLeft
				break;
		}
		graphics.endFill()
		
		rotateControl( rotationCenter )
	}
}
}